{extend name="public/world"}
{block name="style"}{/block}
{block name="container"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/html" id="barDemo">
{if isset($sonAuth['edit'])}
    <input type="checkbox" name="visable" value="{{ d.visable }}" lay-skin="switch" lay-filter="switchStatus" lay-text="启用|禁用" {{ d.visable == 1 ? 'checked' : '' }} data-href="{:url('/setting.SystemMenus/edit')}?id={{ d.id }}">
    <a href="{:url('/setting.SystemMenus/edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs j-iframe-pop" lxb-data="{width: '650px', height: '450px'}" title="修改菜单"><i class="layui-icon">&#xe642;</i></a>
{/if}
{if isset($sonAuth['add'])}
    {{# if(d.type < 4){ }}
    <a href="{:url('/setting.SystemMenus/add')}?id={{ d.id }}" class="layui-btn layui-btn-xs j-iframe-pop" lxb-data="{width: '650px', height: '450px'}" title="添加菜单"><i class="layui-icon">&#xe654;</i></a>
    {{# } }}
{/if}
</script>
<script>
    layui.use(['table'], function() {
        var $ = layui.$,
            table = layui.table;
        var tableIns = table.render({
            elem: '#dataTable',
            url: "{:url('/setting.SystemMenus/index')}",
            method: 'post',
            cols: [
                [
                    { field: 'id', title: 'ID', width: 60, fixed: 'left'}
                    , { field: 'sort', title: '排序', width: 60, fixed: 'left',edit:true}
                    , {
                        field: 'menu_name',
                        title: '菜单名称',
                        width: 220,
                        templet: function(res) {
                            return '<span class="role-name'+res.type+'">' + res.menu_name + '</span>'
                        }
                    }
                    , { field: 'controller', title: '控制器', width: 180}
                    , { field: 'action', title: '方法名', width: 100}
                    , { field: 'url', title: 'URL', width: 200 }
                    , { field: 'icon', title: '图标', width: 180}
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 160 }
                ]
            ],
            page: false
        });
        table.on('edit(dataTable)', function(obj){
            var value = obj.value; //得到修改后的值
            var id = obj.data.id; //所在行的所有相关数据
            $.ajax({
                type: "POST",
                url: "{:url('/setting.SystemMenus/edit')}",
                data: {op:1,id:id,sort:value},
                success: function(res) {
                    if (res.code == 1) {
                        tableIns.reload();
                    }
                }
            });
        });
    });
</script>
{/block}